package com.siloam.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;

import com.siloam.module.Role;

public class RoleDao {
	private SqlSession sqlSession;

	public SqlSession getSqlSession() {
		return sqlSession;
	}

	public void setSqlSession(SqlSession sqlSession) {
		this.sqlSession = sqlSession;
	}

	private String getMapper(String method) {
		return "com.siloam.sqlmap.RoleMapper." + method;
	}
	
	public void add(Role role){
		sqlSession.insert(getMapper("add"), role);
	}
	
	public void update(Role role){
		sqlSession.update(getMapper("update"), role);
	}
	
	public void delete(String ids){
		sqlSession.delete(getMapper("delete"), ids);
	}
	
	public void delete(int id){
		sqlSession.delete(getMapper("deleteOne"), id);
	}
	
	public Role load(int id){
		return sqlSession.selectOne(getMapper("load"), id);
	}
	
	public List<Role> findAll(){
		return sqlSession.selectList(getMapper("findAll"));
	}
	
	public void addRoleNav(int roleId, int navId){
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("roleId", roleId);
		params.put("navId", navId);
		sqlSession.insert(getMapper("addRoleNav"), params);
	}
	
	
}
